package com.wsc.wisdomchinaqinghe.application;

import android.app.Activity;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;

import com.mob.MobApplication;
import com.umeng.analytics.MobclickAgent;
import com.wsc.wisdomchinaqinghe.BuildConfig;
import com.wsc.wisdomchinaqinghe.Tools.DeviceUuidFactory;
import com.wsc.wisdomchinaqinghe.httpUtils.HttpHeadParams;
import com.wsc.wisdomchinaqinghe.javaBean.ApplyTitleListBean;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * @author jaily.zhang
 * @version V1.3.1
 * @Description 全局变量
 * @date 2014-9-3 下午1:55:31
 */
public class MyApplication extends MobApplication {
    private String version;// 软件版本号
    private String Uuid;// 手机物理唯一标识
    private String osType;// 手机操作系统
//    private String imei;// imei 号码
    private String mac;// mac 地址
    private String market;// 应用市场编号

    private ApplicationInfo appInfo;
    private String wscSecretKey;
    private String wscAccessKey;
    private String informationFragmentSelected;// 选中的资讯页面Fragment标记
    private List<String> ModuleId;
    private List<String> ModuleName;
    private List<String> TitleListName;
    private List<Integer> TitleListType;
    private List<ApplyTitleListBean> CenterApplyList;
    public List<Activity> activities;
    private String sourceIntoLoginRegisterActivity;
    private HashMap<String, String> questionMap = new HashMap<>();
    private String locationCity;//高德地图获取到的定位城市
    private String locationDistrict;//高德地图获取到的定位区县
    private String locationAddress="";//定位的具体位置
    private double latitude;//维度
    private double longitude;//精度
    private int selectShouliCenterIndex=0;
    private String IP;


    @Override
    public void onCreate() {
        // TODO Auto-generated method stub
        super.onCreate();
        MobclickAgent.openActivityDurationTrack(false);
        // 得到应用市场渠道编号
        if (market == null) {
            market = getAppInfo().metaData.getString("UMENG_CHANNEL");
            if (market == null)
                market = Integer.toString(getAppInfo().metaData.getInt("UMENG_CHANNEL"));
        }

        // 获取version
        version = BuildConfig.VERSION_NAME;
        // 获取Uuid
        Uuid = new DeviceUuidFactory(getApplicationContext()).getDeviceUuid();
//        // 获取OsType
        osType = getOsVersion();
        // 获取到imei
//        imei = ((TelephonyManager) getSystemService(TELEPHONY_SERVICE)).getDeviceId();
        // 获取MAC地址
        WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
        WifiInfo info = wifi.getConnectionInfo();
        mac = info.getMacAddress();
        wscSecretKey = getAppInfo().metaData.getString("WSC_SECRETKEY");
        wscAccessKey = getAppInfo().metaData.getString("WSC_ACCESSKEY");
        activities = new ArrayList<>();

        // 初始化HttpHeadParams 字段
        initHttpHeadInstance();

    }

    /**
     * @return
     * @throws Exception
     * @Description 获取手机版本号
     * @author jaily.zhang
     */
    private String getOsVersion() {
        // 获取packagemanager的实例
        return "Android " + android.os.Build.VERSION.RELEASE + "," + android.os.Build.MANUFACTURER + "," + android.os.Build.MODEL;
    }

    public String getWscSecretKey() {
        return wscSecretKey;
    }

    public String getWscAccessKey() {
        return wscAccessKey;
    }

    public String getInformationFragmentSelected() {
        return informationFragmentSelected;
    }

    public void setInformationFragmentSelected(String informationFragmentSelected) {
        this.informationFragmentSelected = informationFragmentSelected;
    }

    public ApplicationInfo getAppInfo() {
        if (appInfo == null) {
            try {
                appInfo = getPackageManager().getApplicationInfo(getPackageName(), PackageManager.GET_META_DATA);

            } catch (NameNotFoundException e) {

            }
        }
        return appInfo;
    }

    public List<String> getModuleId() {
        return ModuleId;
    }

    public void setModuleId(List<String> eightModuleId) {
        this.ModuleId = eightModuleId;
    }

    public List<String> getModuleName() {
        return ModuleName;
    }

    public void setModuleName(List<String> eightModuleName) {
        this.ModuleName = eightModuleName;
    }

    /**
     * 初始化 httpHeadInsatnce
     */
    private void initHttpHeadInstance() {
        HttpHeadParams.getInstance().setAccessKey(wscAccessKey);
        HttpHeadParams.getInstance().setSecretKey(wscSecretKey);
        HttpHeadParams.getInstance().setUuid(Uuid);
        HttpHeadParams.getInstance().setVersion(version);
        HttpHeadParams.getInstance().setOs(osType);
        HttpHeadParams.getInstance().setMarket(market);
        HttpHeadParams.getInstance().setMac(mac);
//        HttpHeadParams.getInstance().setImei(imei);
    }

    public String getSourceIntoLoginRegisterActivity() {
        return sourceIntoLoginRegisterActivity;
    }

    public void setSourceIntoLoginRegisterActivity(String sourceIntoLoginRegisterActivity) {
        this.sourceIntoLoginRegisterActivity = sourceIntoLoginRegisterActivity;
    }

    public HashMap<String, String> getQuestionMap() {
        return questionMap;
    }

    public void setQuestionMap(HashMap<String, String> questionMap) {
        this.questionMap = questionMap;
    }

    public String getLocationCity() {
        return locationCity;
    }

    public void setLocationCity(String locationCity) {
        this.locationCity = locationCity;
    }

    public String getLocationDistrict() {
        return locationDistrict;
    }

    public void setLocationDistrict(String locationDistrict) {
        this.locationDistrict = locationDistrict;
    }

    public String getVersion() {
        return version;
    }

    public void setVersion(String version) {
        this.version = version;
    }

    public double getLatitude() {
        return latitude;
    }

    public void setLatitude(double latitude) {
        this.latitude = latitude;
    }

    public double getLongitude() {
        return longitude;
    }

    public void setLongitude(double longitude) {
        this.longitude = longitude;
    }

    public List<String> getTitleListName() {
        return TitleListName;
    }

    public void setTitleListName(List<String> titleListName) {
        TitleListName = titleListName;
    }

    public List<Integer> getTitleListType() {
        return TitleListType;
    }

    public void setTitleListType(List<Integer> titleListType) {
        TitleListType = titleListType;
    }

    public List<ApplyTitleListBean> getCenterApplyList() {
        return CenterApplyList;
    }

    public void setCenterApplyList(List<ApplyTitleListBean> centerApplyList) {
        CenterApplyList = centerApplyList;
    }

    public int getSelectShouliCenterIndex() {
        return selectShouliCenterIndex;
    }

    public void setSelectShouliCenterIndex(int selectShouliCenterIndex) {
        this.selectShouliCenterIndex = selectShouliCenterIndex;
    }

    public String getLocationAddress() {
        return locationAddress;
    }

    public void setLocationAddress(String locationAddress) {
        this.locationAddress = locationAddress;
    }

    public String getIP() {
        return IP;
    }

    public void setIP(String IP) {
        this.IP = IP;
    }
}